<?php
namespace Mob \ Model;

use Think \ Model;
use Think \ Hook;
/**推荐模型
 * Class InfoModel
 */

require_once ('./Application/Mob/Common/function.php');

class ChooseModel extends Model {
  //创建推荐信息
  public function creator($title,$contents,$urllink,$attach_ids,$createUid,$schooId=10183,$type=1)
  {
   $data['serialno']=getSerialno(18);
   $data['title']=$title;
   $data['contents']=$contents;
   $data['urllink']=$urllink;
   $data['is_img']=empty($attach_ids)?0:1;
   $data['attach_ids']=$attach_ids;
   $data['createUid']=$createUid;
   $data['type']=$type;
   $data['createTime']=time();
   $data['schooId']=$schooId;
   if($this->add($data))
   {
   return $data['serialno'];
   }
  }
  //获取推荐详情
  public function get_chooseInfo($serialno,$schooId=10183)
  {
   return $this->where(array('serialno'=>$serialno,'schooId'=>$schooId,'status'=>1))->field('serialno,title,contents,urllink,createUid,browseNum,createTime,type,clickNum,attach_ids,is_img,schooId')->find();


  }
  //添加浏览记录
  public function addBrowseRecord($serialno)
  {
   $this->where(array('serialno'=>$serialno,'status'=>1))->setInc('browseNum');
   D('Browse')->addBrowseLog(5,$serialno);
  }
  //添加点击记录
  public function addClickRecord($serialno,$clickUrl)
  {
   $this->where(array('serialno'=>$serialno,'status'=>1))->setInc('clickNum');
   D('Click')->addRecord(5,$serialno,$clickUrl);
  }
  //更新评论数
  public function addCommentNum($serialno)
  {
 $this->where(array('serialno'=>$serialno,'status'=>1))->setInc('commentNum');
  }
  //获取所有推荐数据
  public function get_allChoose($schooId=10183)
  {
  return $this->where(array('schooId'=>$schooId,'status'=>1))->field('serialno,title,contents,urllink,createUid,browseNum,createTime,type,clickNum,attach_ids,is_img,schooId,commentNum')->order('createTime desc')->select();

  }
  //获取当日推荐信息
  public function get_todayChoose($schooId=10183,$type=1)
  {
  $startTime = strtotime(date('Y-m-d'));
  $endTime = $startTime+86400;
  return $this->query("select serialno,title,contents,urllink,createUid,browseNum,createTime,type,clickNum,attach_ids,is_img,schooId from ocenter_choose where createTime >= $startTime and createTime < $endTime and status = 1 and schooId = $schooId and type = $type limit 1 ")[0];
  }












}